package br.com.jogodavelha.activitys;

import br.com.jogodavelha.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class SelecionaNomeJogadoresActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.seleciona_nome_jogadores_layout);

		Button b = (Button)findViewById(R.id.btnAvancarNmJog);
		final EditText txtPlayer1 = (EditText)findViewById(R.id.txtNmPlayer1);
		final EditText txtPlayer2 = (EditText)findViewById(R.id.txtNmPlayer2);

		final Intent intent = this.getIntent();

		if(intent.getExtras().get("modo").equals("OnePlayer")){
			TextView txt = (TextView)findViewById(R.id.textViewPlayer2);
			txtPlayer2.setVisibility(View.INVISIBLE);
			txt.setVisibility(View.INVISIBLE);
		}

		b.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent i = new Intent(SelecionaNomeJogadoresActivity.this, JogoActivity.class);
				i.putExtra("modo", intent.getExtras().get("modo").toString());
				i.putExtra("player1", txtPlayer1.getEditableText().toString());

				if(intent.getExtras().get("dificuldade") != null){
					i.putExtra("dificuldade", intent.getExtras().get("dificuldade").toString());
				}
				if(intent.getExtras().get("modo").equals("TwoPlayer")){
					i.putExtra("player2", txtPlayer2.getEditableText().toString());
				}

				startActivity(i);				
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.seleciona_nome_jogadores, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
